package com.maori.languageapp.discover.word;

import java.util.ArrayList;
import java.util.HashMap;
import com.maori.languageapp.R;
import com.maori.languageapp.consts.ImageLoader;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Maori_Discover_Word_ImageList_Adapter extends BaseAdapter {
	private static final String TAG = null;
	// Declare Variables
	Context context;
	LayoutInflater inflater;
	ArrayList<HashMap<String, String>> data;
	ImageLoader imageLoader;

	public Maori_Discover_Word_ImageList_Adapter(Context context,
			ArrayList<HashMap<String, String>> arraylist) {
		this.context = context;
		data = arraylist;
		imageLoader = new ImageLoader(context);

	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		// Declare Variables
		TextView first_name,last_name,Discover_example_likes;
		ImageView flag,userimage;
		Button setDefImageAction,setLikeImageAction;

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View itemViewImages = inflater.inflate(R.layout.languageapp_discover_image,
				parent, false);
		
		// Get the position from the results
		HashMap<String, String> resultp = new HashMap<String, String>();
		resultp = data.get(position);
		// Locate the ImageView in listview_item.xml
		first_name = (TextView) itemViewImages.findViewById(R.id.addnew);
		last_name = (TextView) itemViewImages.findViewById(R.id.addnew4);
		flag = (ImageView) itemViewImages.findViewById(R.id.ImageView_example);
		userimage = (ImageView) itemViewImages.findViewById(R.id.userimggriditem);
		
		Discover_example_likes = (Button) itemViewImages.findViewById(R.id.Discover_example_likes);
		setDefImageAction = (Button) itemViewImages.findViewById(R.id.setDefAction);
		setLikeImageAction = (Button) itemViewImages.findViewById(R.id.setLikeAction);
		// Capture position and set results to the ImageView
		// Passes flag images URL into ImageLoader.class to download and cache
		// images
		imageLoader.DisplayImage(resultp.get(Maori_Discover_Word_Details.IMAGEM_Source),flag);
		imageLoader.DisplayImage(resultp.get(Maori_Discover_Word_Details.IMAGEMID),userimage);
		first_name.setText(resultp.get(Maori_Discover_Word_Details.IMAGEfirst_name));
		last_name.setText(resultp.get(Maori_Discover_Word_Details.IMAGElast_name));
		Discover_example_likes.setText("Likes ("+resultp.get(Maori_Discover_Word_Details.IMAGETotalsLikes)+")");
		setLikeImageAction.setText(resultp.get(Maori_Discover_Word_Details.IMAGENID)+"/"+resultp.get(Maori_Discover_Word_Details.IMAGEUID));
		setDefImageAction.setText(resultp.get(Maori_Discover_Word_Details.IMAGENID)+"/"+resultp.get(Maori_Discover_Word_Details.IMAGEUID) + "/"+ resultp.get(Maori_Discover_Word_Details.IMAGENM_ID));
		// Capture button clicks on ListView items
		return itemViewImages;
	}
	
}
